package com.ado.abyss.core.manager.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ado.abyss.core.dal.dao.SysRoleMenuMapper;
import com.ado.abyss.core.dal.model.SysRoleMenu;
import com.ado.abyss.core.manager.SysRoleMenuManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(value = "sysRoleMenuManager")
public class SysRoleMenuManagerImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuManager{

    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper ;

    @Override
    public List<SysRoleMenu> findByRoleId(Long roleId) {
        return sysRoleMenuMapper.findByRoleId(roleId);
    }

    @Override
    @Transactional
    public boolean saveRoleMenuBatch(List<SysRoleMenu> records) {
        boolean flag = false ;
        int count = 0 ;
        for (SysRoleMenu sysRoleMenu : records) {
            int result = sysRoleMenuMapper.insertSelective(sysRoleMenu) ;
            if(result == 1) {
                count++ ;
            }
        }
        if(count == records.size()+1) {
            flag = true ;
        }
        return flag;
    }

    @Override
    public List<SysRoleMenu> findAll() {
        return sysRoleMenuMapper.getAll();
    }
}
